import numpy as np

x = np.array([[1, 2], [3, 4], [5, 6]])
print(x)
y = x[[0, 1, 2], [0, 1, 0]]
print(y)

a = np.zeros((9, 9), dtype=int)
print(a)

a = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]])
print(a)
print(a.shape)

#  行索引是 [0,0] 和 [3,3]，而列索引是 [0,2] 和 [0,2]。
rows = np.array([[0, 0], [3, 3]])
print(rows)
cols = np.array([[0, 2], [0, 2]])
print(cols)
y = a[rows, cols]
print(y)

a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
b = a[1:4, 1:3]
print(a)
print(b)
c = a[1:3, [0, 2]]
print(c)
d = a[..., 2:]
print(d)

# 布尔索引
print(a[a > 5])

# 使用了 ~（取补运算符）来过滤 NaN。
a = np.array([np.nan, 1, 2, 3])
print(a[~np.isnan(a)])

# 如何从数组中过滤掉非复数元素。
a = np.array([1, 2 + 6j, 5, 3.5 + 5j])
print(a[np.iscomplex(a)])

a = np.arange(9)
print(a)
b = a[[0, 6]]
print(b)

a = np.arange(32).reshape((8, 4))
print(a)
# 二维数组读取指定下标对应的行
print(a[[1, 2, 3, 4]])

print(a[np.ix_([1], [1])])
